#!/bin/sh
##下载最新的曲库同步到BX_VOD.TB_Song中


datetime=`date +%F" "%T`
timestamp=`date "+%s"`

httpurl="http://e.beidousat.com:5600"

src_fn="/update/db_rsync/song.sql"
dest_fn="/server/scripts/song.sql"
logfile="/server/scripts/versionupdate.log"


function http_download() {
    local src_fn=$1
    local dest_fn=$2
    curl "$httpurl$src_fn" -o $dest_fn >>/dev/null && \
    echo 0 || echo 1
}

function logging(){
# Usage: logging ret "日志内容" "error日志内容"
[ $1 -eq 0 ]&&echo -e "\033[32;1m $2 \033[0m" | tee -a $logfile ||echo -e "\033[41;37;5m $3 \033[0m" | tee -a $logfile
}

down_stat=`http_download $src_fn $dest_fn`
logging $down_stat "$datetime ----$src_fn download finish" "$datetime ----$src_fn download failed"
grep "BX_VOD" $dest_fn && mysql BX_VOD <$dest_fn || echo -e "\033[41;37;5m 导入曲库失败 \033[0m"
